<template>
	<view class="container home-pd">
		<view class="card">
			<uv-form labelPosition="left" ref="form">
				<uv-form-item label-width="200rpx" label="任务ID">
					{{item.id??'--'}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="任务状态">
					{{tagName}}
				</uv-form-item>
				<uv-form-item v-if="item.purchasePicUrl" class="column" label-width="200rpx" label="采购凭证">
					<uv-upload :deletable="false" :fileList="[{
						url:item.purchasePicUrl
					}]" multiple :maxCount="1"></uv-upload>
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="采购说明">
					{{item.purchaseDescription??"--"}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="商品名称">
					{{item.productListName??"--"}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="区域大仓">
					{{item.cwcName??"--"}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="供应商名称">
					{{item.productListName??"--"}}
				</uv-form-item>
			</uv-form>
		</view>
		<view class="card">
			<uv-form labelPosition="left" ref="form">
				<uv-form-item label-width="200rpx" label="采购数量">
					{{item.quantity}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="已处理数量">
					{{item?.quantityProcessed??"--"}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="待入库数量">
					{{item.stockPendingNum??"--"}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="采购成本总价">
					{{item.totalCost??"--"}}元
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="综合成本单价">
					{{item.actualCost??"--"}}元
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="入库成本单价">
					{{item.stockCost??"--"}}元
				</uv-form-item>
			</uv-form>
		</view>
		<view class="card">
			<uv-form labelPosition="left" ref="form">
				<uv-form-item label-width="200rpx" label="退货数量">
					{{item.quantityReturned??"--"}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="退货说明">
					{{item.returnDescribe??'--'}}
				</uv-form-item>
			</uv-form>
		</view>
		<view class="card">
			<uv-form labelPosition="left" ref="form">
				<uv-form-item label-width="200rpx" label="导入批次号">
					{{item.batchNumber??'--'}}
				</uv-form-item>
				<uv-form-item v-if="item.picUrl" class="column" label-width="200rpx" label="入库凭证">
					<uv-upload :deletable="false" :fileList="[{
						url:item.picUrl
					}]" multiple :maxCount="1"></uv-upload>
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="入库说明">
					{{item.description??"--"}}
				</uv-form-item>
			</uv-form>
		</view>
		<view class="card">
			<uv-form labelPosition="left" ref="form">
				<uv-form-item label-width="200rpx" label="创建人">
					{{item.creatorName??"--"}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="创建时间">
					{{tools.timestampToTime(item.createTime,'yyyy-MM-dd hh:mm:ss')}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="修改人">
					{{item.updaterName ??"--"}}
				</uv-form-item>
				<uv-form-item label-width="200rpx" label="修改时间">
					{{tools.timestampToTime(item.updateTime,'yyyy-MM-dd hh:mm:ss')}}
				</uv-form-item>
			</uv-form>
		</view>
		<view class="button-group">
			<view style="gap: 20rpx;" class="flex flex-justify-center"> 
			<!-- -->
				<view v-if="item.taskStatus==1" @click="goPage('/pages/task/pages/return/index')"
					class="return flex flex-items-center flex-justify-center flex-1">退货</view>
					<!--  -->
				<view @click="refuse" v-if="item.taskStatus==0" class="refuse flex flex-items-center flex-justify-center flex-1">拒绝入库</view>
			</view>
			<view v-if="item.taskStatus==0" @click="goPage(`/pages/task/pages/accept/index`)"
				class="accept button flex flex-justify-center flex-items-center">入库确认</view>
		</view>
	</view>
</template>

<script setup>
	import tools from '../../../../utils/tools';
	import { update } from '@/api/task.js';
	let item;
	let fileList = ref([]);
	const tabsList = ref([{
		name: '等待入库',
		value: 0,
		className: "tag-danger"
	}, {
		name: '入库成功',
		value: 1,
		className: "tag-success"
	}, {
		name: '拒绝入库',
		value: 2,
		className: "tag-error"
	}, {
		name: '结束入库',
		value: 3,
		className: ""
	}]);
	let tagName = computed(() => {
		let arr = tabsList.value.filter(i => i.value !== '');
		return (arr.find(i => i.value == Number(item.taskStatus)) || {})?.name;
	})
	function refuse(){
		update({
			taskStatus: "1",
			id:item.id
		}).then(res=>{
			if(res.code==0){
				uni.showToast({
					title:'操作成功',
					icon:'none'
				});
				setTimeout(()=>{
					uni.navigateBack()
				},1000)
			}
		})
	}
	function afterRead(event) {
		let filePath = event.file[0].url;
		tools.updateFile({
			filePath
		}).then(res => {
			fileList.value.push(res)
		})
	}

	function deletePic(event) {
		fileList.value = [];
	}

	function goReturn() {
		uni.navigateTo({
			url: "/pages/task/pages/return/index"
		})
	}

	function goPage(url) {
		uni.navigateTo({
			url: `${url}?item=${encodeURIComponent(JSON.stringify(item))}`
		})
	}

	onLoad((option) => {
		item = JSON.parse(decodeURIComponent(option.item));
		console.log(item)
	})
</script>

<style lang="scss" scoped>
	:deep(.uv-form-item__body) {
		padding: 38rpx 0 !important;
	}

	.column {
		:deep(.uv-form-item__body) {
			flex-direction: column !important;
			padding: 24rpx 0 !important;
		}

		:deep(.uv-form-item__body__right) {
			margin-top: 24rpx;
		}
	}

	:deep(.uv-form-item__body__left__content__required) {
		right: 10rpx;
		left: inherit !important;
	}

	:deep(.uv-form-item__body__left__content__label) {
		font-weight: 400;
		font-size: 28rpx;
		color: #3C3F4D;
	}

	@import "index.scss";
</style>